home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / OutOfPhase1.01Source / OutOfPhase Folder / TrackBackgroundSaver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  4.7 KB  |  133 lines  |  [TEXT/KAHL]

  1. /* TrackBackgroundSaver.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "TrackBackgroundSaver.h"
  31. #include "BufferedFileInput.h"
  32. #include "BufferedFileOutput.h"
  33. #include "Memory.h"
  34. #include "Array.h"
  35. #include "TrackObject.h"
  36.  
  37.  
  38. /* Background Display Subblock Format: */
  39. /*   4-byte little endian number of tracks in the background of this track */
  40. /*   for each of those: */
  41. /*     4-byte index of the track to be in the background */
  42. /*       the index is respective to the order in which the tracks were loaded */
  43. /*       from the file, so 0 is the first track, 1 is the second, and so on. */
  44.  
  45.  
  46. /* save the information describing which tracks are in the background (greyed) */
  47. FileLoadingErrors        SaveBackgroundTrackInfo(struct TrackObjectRec* TrackObj,
  48.                                             struct BufferedOutputRec* Output,
  49.                                             struct ArrayRec* OrderedListOfAllTracks)
  50.     {
  51.         ArrayRec*                    Backgrounds;
  52.         long                            Scan;
  53.         long                            Limit;
  54.  
  55.         CheckPtrExistence(TrackObj);
  56.         CheckPtrExistence(Output);
  57.         CheckPtrExistence(OrderedListOfAllTracks);
  58.  
  59.         Backgrounds = TrackObjectGetBackgroundList(TrackObj); /* actual thing */
  60.         CheckPtrExistence(Backgrounds);
  61.  
  62.         Limit = ArrayGetLength(Backgrounds);
  63.         if (!WriteBufferedUnsignedLongLittleEndian(Output,Limit))
  64.             {
  65.                 return eFileLoadDiskError;
  66.             }
  67.  
  68.         for (Scan = 0; Scan < Limit; Scan += 1)
  69.             {
  70.                 long                            Index;
  71.  
  72.                 Index = ArrayFindElement(OrderedListOfAllTracks,
  73.                     ArrayGetElement(Backgrounds,Scan));
  74.                 ERROR(Index < 0,PRERR(ForceAbort,
  75.                     "SaveBackgroundTrackInfo:  track not on master list"));
  76.                 if (!WriteBufferedUnsignedLongLittleEndian(Output,Index))
  77.                     {
  78.                         return eFileLoadDiskError;
  79.                     }
  80.             }
  81.  
  82.         return eFileLoadNoError;
  83.     }
  84.  
  85.  
  86. /* load information describing which tracks are in the background */
  87. FileLoadingErrors        LoadBackgroundTrackInfo(struct TrackObjectRec* TrackObj,
  88.                                             struct BufferedInputRec* Input,
  89.                                             struct ArrayRec* OrderedListOfAllTracks)
  90.     {
  91.         unsigned long            Limit;
  92.         unsigned long            Scan;
  93.         long                            TotalTrackCount;
  94.  
  95.         CheckPtrExistence(TrackObj);
  96.         CheckPtrExistence(Input);
  97.         CheckPtrExistence(OrderedListOfAllTracks);
  98.  
  99.         if (!ReadBufferedUnsignedLongLittleEndian(Input,&Limit))
  100.             {
  101.                 return eFileLoadDiskError;
  102.             }
  103.  
  104.         TotalTrackCount = ArrayGetLength(OrderedListOfAllTracks);
  105.         for (Scan = 0; Scan < Limit; Scan += 1)
  106.             {
  107.                 unsigned long            Value;
  108.                 TrackObjectRec*        OneToBackground;
  109.  
  110.                 if (!ReadBufferedUnsignedLongLittleEndian(Input,&Value))
  111.                     {
  112.                         return eFileLoadDiskError;
  113.                     }
  114.                 if ((Value < 0) || (Value >= TotalTrackCount))
  115.                     {
  116.                         return eFileLoadBadFormat;
  117.                     }
  118.                 OneToBackground = (TrackObjectRec*)ArrayGetElement(OrderedListOfAllTracks,Value);
  119.                 CheckPtrExistence(OneToBackground);
  120.                 if (-1 != ArrayFindElement(TrackObjectGetBackgroundList(TrackObj),
  121.                     OneToBackground))
  122.                     {
  123.                         return eFileLoadBadFormat; /* can't have multiple ones */
  124.                     }
  125.                 if (!TrackObjectAddBackgroundObj(TrackObj,OneToBackground))
  126.                     {
  127.                         return eFileLoadOutOfMemory;
  128.                     }
  129.             }
  130.  
  131.         return eFileLoadNoError;
  132.     }
  133.